#pragma once
#include "Game/Process/RenderProcess.h"
#include "Render/Tradition/ComputePipeline.h"
#include "Render/Shader/RHIDescriptor.h"
#include "Render/Tradition/RHIFramebuffer.h"
#include "../LocalEntity.h"
#include "../LocalShader.h"
#include "../ResourceProcess.h"
#include "../LocalScene.h"


class DdgiRayTraceProcess : public RenderProcess
{
	DECLARE_PROCESS(DdgiRayTraceProcess)

	struct PushConstants
	{
		glm::mat4 randomOrientation;
		uint32 frame;
		uint32 infiniteBounces;
		float giIntensity;
	};

public:

	float mProbeDistance;
	float mDepthSharpness;
	float mHysteresis;
	float mNormalBias;
	float mEnergyPreservation;
	int32 mIrradianceOctSize;
	int32 mDepthOctSize;
	int32 mRaysPerProbe;
	bool mVisibilityTest;
	glm::ivec3 mProbeCounts;

	bool mInfiniteBounces;

	PushConstants mPushConstants;

protected:

	virtual void OnInit() override;

	virtual void OnTick(float deltaTime) override;

	virtual void OnResize() override;

protected:

	LocalScene* mLocalScene;

	ResourceProcess* mResourceProcess;



	RefCountPtr<RHIBuffer> mDdgiUbo;



	RefCountPtr<RHITexture> mRadianceImage;

	RefCountPtr<RHITexture> mDirectionDistanceImage;



	std::array<RefCountPtr<RHITexture>, 2> mIrradianceImage;

	std::array<RefCountPtr<RHITexture>, 2> mDepthImage;



	ShaderPtr<DdgiRayTraceRgenShader> mRgenShader;

	ShaderPtr<DdgiRayTraceRchitShader> mRchitShader;

	ShaderPtr<DdgiRayTraceRmissShader> mRmissShader;

	RefCountPtr<RHIDescriptor> mDescriptor;

	DescriptorMask mDescriptorMask;
	
	std::array<DescriptorMask, 2> mImageDescriptorMask;

	RefCountPtr<RayTracingPipeline> mPipeline;

};
